package com.demo.service;

import com.demo.model.Rule;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;

/**
 * @Author LeeXyan
 * @Date 2017/8/31 17:15
 */
@Component
public class IntegralFactoryImpl implements IntegralFactory {

    @Override
    public Double IntegralSum(BigDecimal mo, Rule rule, Double integralSum) {
        if (rule.getRuleM().equals(BigDecimal.ZERO)) {
            integralSum = integralSum + rule.getIntegral();
        } else {
            integralSum = integralSum + mo.divide(rule.getRuleM()).doubleValue() * rule.getIntegral();
        }
        return integralSum;
    }
}
